package com.gdou.service.impl;

import com.gdou.commons.Result;
import com.gdou.mapper.ShipMapper;
import com.gdou.mapper.ShipStatusMapper;
import com.gdou.mapper.UserMapper;
import com.gdou.model.HumidityAndTimes;
import com.gdou.model.ShipNamesAndUserCounts;
import com.gdou.model.TemperatureAndTimes;
import com.gdou.model.vo.ShipStatusQueryVo;
import com.gdou.service.EcharsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EcharsServiceImpl implements EcharsService {
    @Autowired
    private ShipMapper shipMapper;

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private ShipStatusMapper shipStatusMapper;

    @Override
    public Result findShipWithUserCount() {

        String[] names = shipMapper.selectNamesOrderById();

        Long[] counts = userMapper.selectUserCountsOrderByShip_id();

        Result result = new Result();
        ShipNamesAndUserCounts data = new ShipNamesAndUserCounts();
        data.setNames(names);
        data.setCounts(counts);
        result.setData(data);
        return result;
    }

    // 查询所有消息
    @Override
    public Result findAllInfoByShipId(Long shipId) {
        List<ShipStatusQueryVo> shipStatusQueryVoList =  shipStatusMapper.selectShipStatusQueryVo(shipId);
        Result result = new Result();
        result.setData(shipStatusQueryVoList);
        return result;
    }

    // 查询温度
    @Override
    public Result findTemperaturesByShipId(Long shipId) {
        /*温度 和 时间*/
        List<TemperatureAndTimes> temperatureAndTimesList =  shipStatusMapper.selecTemperaturesAndTimes(shipId);
        Result result = new Result();
        result.setData(temperatureAndTimesList);
        return result;
    }

    // 查询湿度
    @Override
    public Result findHumiditiesByShipId(Long shipId) {
        List<HumidityAndTimes> HumidityAndTimesList =  shipStatusMapper.selectHumidityAndTimes(shipId);
        Result result = new Result();
        result.setData(HumidityAndTimesList);
        return result;
    }
}
